package com.xy.tianyu.module.picture.adapter

import android.view.View
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.listener.OnItemClickListener
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.google.android.exoplayer2.C
import com.xy.tianyu.R
import com.xy.tianyu.module.picture.activity.PicHotDayDetailActivity
import com.xy.tianyu.module.picture.bean.ItemX
import com.xy.tianyu.module.picture.bean.PicSetItem

/**
 * @time 2020/10/12 16:30
 * @class 描述:
 */
class PicSetAdapter(layoutResId: Int, data:MutableList<PicSetItem>):BaseQuickAdapter<PicSetItem,BaseViewHolder>(layoutResId,data) {
    override fun convert(holder: BaseViewHolder, item: PicSetItem) {
       holder.setText(R.id.tv_pic_set_name,item.keyword)

       val list = item.items
       if (!list.isNullOrEmpty()){
           val ryPicSetChild = holder.getView<RecyclerView>(R.id.ry_pic_set_child)
           ryPicSetChild.layoutManager = GridLayoutManager(context,3)
           val childList = arrayListOf<ItemX>()
           childList.addAll(list)
           val picSetChildAdapter = PicSetChildAdapter(R.layout.item_pic_set_child,childList)
           ryPicSetChild.adapter = picSetChildAdapter

           picSetChildAdapter.setOnItemClickListener(object : OnItemClickListener{
               override fun onItemClick(
                   adapter: BaseQuickAdapter<*, *>,
                   view: View,
                   position: Int
               ) {
                    PicHotDayDetailActivity.actionStart3(context,3,childList,childList[position])
               }

           })
       }
    }
}